<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="会员编号" prop="memberId">-->
<!--      <el-input v-model="dataForm.memberId" placeholder="会员编号"></el-input>-->
<!--    </el-form-item>-->
    <el-form-item label="会员姓名" prop="memberName">
      <el-input v-model="dataForm.memberName" placeholder="会员姓名"></el-input>
    </el-form-item>
    <el-form-item label="会员电话" prop="memberPhone">
      <el-input v-model="dataForm.memberPhone" placeholder="会员电话"></el-input>
    </el-form-item>
<!--    <el-form-item label="性别" prop="memberSex">-->
<!--      <el-input v-model="dataForm.memberSex" placeholder="性别"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="性别" prop="memberSex">
        <el-select v-model="dataForm.memberSex" placeholder="请选择">
          <el-option label="男" value="男"></el-option>
          <el-option label="女" value="女"></el-option>
        </el-select>
      </el-form-item>

    <el-form-item label="年龄" prop="memberAge">
      <el-input v-model="dataForm.memberAge" placeholder="年龄"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="memberIdnum">
      <el-input v-model="dataForm.memberIdnum" placeholder="身份证号"></el-input>
    </el-form-item>
<!--    <el-form-item label="创建时间" prop="createTime">-->
<!--      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="更新时间" prop="updateTime">-->
<!--      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>-->
<!--    </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          memberId: '',
          memberName: '',
          memberPhone: '',
          memberSex: '',
          memberAge: '',
          memberIdnum: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          memberId: [
            { required: true, message: '会员编号不能为空', trigger: 'blur' }
          ],
          memberName: [
            { required: true, message: '会员姓名不能为空', trigger: 'blur' }
          ],
          memberPhone: [
            { required: true, message: '会员电话不能为空', trigger: 'blur' }
          ],
          memberSex: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          memberAge: [
            { required: true, message: '年龄不能为空', trigger: 'blur' }
          ],
          memberIdnum: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_member/bsmember/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberId = data.bsMember.memberId
                this.dataForm.memberName = data.bsMember.memberName
                this.dataForm.memberPhone = data.bsMember.memberPhone
                this.dataForm.memberSex = data.bsMember.memberSex
                this.dataForm.memberAge = data.bsMember.memberAge
                this.dataForm.memberIdnum = data.bsMember.memberIdnum
                this.dataForm.createTime = data.bsMember.createTime
                this.dataForm.updateTime = data.bsMember.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_member/bsmember/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'memberId': this.dataForm.memberId,
                'memberName': this.dataForm.memberName,
                'memberPhone': this.dataForm.memberPhone,
                'memberSex': this.dataForm.memberSex,
                'memberAge': this.dataForm.memberAge,
                'memberIdnum': this.dataForm.memberIdnum,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>



